package process;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class MainProcessPSChunck {
	
	public String getStringFrombuf(ByteBuffer buffer){
		String line="";
		while (buffer.hasRemaining()) {
    		//System.out.print((char) buf.get());
    		line+=(char) buffer.get();
    		}
        buffer.clear();
        return line;
	}
	public static void main(String[] args) throws IOException {
		/*Extracted from:
		 * http://stackoverflow.com/questions/1605332/java-nio-filechannel-versus-fileoutputstream-performance-usefulness
		 * See other options in:
		 * http://www.kodejava.org/examples/592.html
		 * http://www.java2s.com/Tutorial/Java/0180__File/UsingFileChanneltoreadtextfile.htm
		 */
		MainProcessPSChunck processPSChunck=new MainProcessPSChunck();		
		/*Extracted from:
		 * http://stackoverflow.com/questions/1605332/java-nio-filechannel-versus-fileoutputstream-performance-usefulness
		 */
		File file = new File("C:\\Proyecto\\reviewsNew.txt");
        File oFile = new File("C:\\Proyecto\\out.txt");

        FileInputStream is = new FileInputStream(file);
        FileOutputStream fos = new FileOutputStream(oFile);
        FileChannel f = is.getChannel();
        FileChannel f2 = fos.getChannel();

        ByteBuffer buf = ByteBuffer.allocateDirect(64 * 1024);
        long len = 0;
        while((len = f.read(buf)) != -1) {
                buf.flip();
                f2.write(buf);
                buf.clear();
        }
        f2.close();
        f.close();
	}

}
